import net.spreadshirt.util.Observer;
import net.spreadshirt.util.Observable;
import net.spreadshirt.logger.Logger;
import net.spreadshirt.logger.LogMessage;

/**
 * An observer of the Logger class. When a movie is played in
 * the Flash authoring tool's Test Movie mode, this class displays
 * log messages in the Output panel.
 */
class net.spreadshirt.logger.OutputPanelView implements Observer {

	// The log that this object is observing.
	private var log:Logger;

	/**
	 * Constructor
	 */
	public function OutputPanelView(l:Logger) {
		log = l;
	}

	/**
	 * Invoked when the log changes. For details, see the
	 * Observer interface.
	 */
	public function update(o:Observable, infoObj:Object):Void {
		// Cast infoObj to a LogMessage instance for type checking.
		var logMsg:LogMessage = LogMessage(infoObj);
		trace(Logger.getLevelDesc(logMsg.getLevel()) + ": "
			+ logMsg.getMessage());
	}

	public function destroy():Void {
		log.removeObserver(this);
	}

}
